//
//  TMGMonthReportController.m
//  TMGold
//
//  Created by Mac on 2017/12/13.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGMonthReportController.h"
#import "STWebViewController.h"
@interface TMGMonthReportController ()
@property(nonatomic, strong) STButton                     *yerarButton;
@property(nonatomic, strong) STButton                     *monthButton;
@end

@implementation TMGMonthReportController
#pragma mark --vc 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"运营报告";
    [self configSubView];
    self.tableView.frame = CGRectMake(0, 64 + 44, UIScreenWidth, UIScreenHeight - 64 - 44);
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.yerarButton.selected = NO;
    self.monthButton.selected = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    NSString * time = [NSDate st_localCurrentDate].st_yyyyMMByLineWithDate;
    NSString * year = [time componentsSeparatedByString:@"-"].firstObject;
    NSString * month = [time componentsSeparatedByString:@"-"].lastObject;
    self.yerarButton = [[STButton alloc] initWithFrame:CGRectMake(0, 64, UIScreenWidth / 2, 44)
                                                     title:[NSString stringWithFormat:@"%@年",year]
                                                titleColor:TM_firstTextColor
                                                 titleFont:15
                                              cornerRadius:0
                                           backgroundColor:[UIColor whiteColor]
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"02"]];
    self.yerarButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.yerarButton setImage:[UIImage imageNamed:@"02"] forState:UIControlStateSelected];
    [self.yerarButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedYearButton];
    }];
    [self.yerarButton makeImageRight];
    [self.view addSubview:self.yerarButton];
    
    self.monthButton = [[STButton alloc] initWithFrame:CGRectMake( UIScreenWidth / 2, 64, UIScreenWidth / 2, 44)
                                                 title:[NSString stringWithFormat:@"%@月",month]
                                            titleColor:TM_firstTextColor
                                             titleFont:15
                                          cornerRadius:0
                                       backgroundColor:[UIColor whiteColor]
                                       backgroundImage:nil
                                                 image:[UIImage imageNamed:@"02"]];
    self.monthButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.monthButton setImage:[UIImage imageNamed:@"02"] forState:UIControlStateSelected];
    [self.monthButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedMonthButton];
    }];
    [self.monthButton makeImageRight];
    [self.view addSubview:self.monthButton];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    cell.textLabel.textColor = UIColorFromRGBA(0x333333);
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
    cell.detailTextLabel.textColor = UIColorFromRGBA(0x999999);
    
    cell.textLabel.text = @"黄金口袋2017年10月报告";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    STWebViewController * webvc = [[STWebViewController alloc] initWithUrl:@"https://www.aliyun.com/?utm_medium=text&utm_source=bdbrand&utm_campaign=bdbrand&utm_content=se_32492"];
    webvc.progressBackgroundColor = [UIColor whiteColor];
    webvc.progressTintColor = TM_orangeColor;
    webvc.forceTitle = @"月报详情";
    [self.navigationController pushViewController:webvc animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Private Method
- (NSArray*)yearArray{
    NSString * time = [NSDate st_localCurrentDate].st_yyyyMMByLineWithDate;
    NSString * year = [time componentsSeparatedByString:@"_"].firstObject;
    int yerarNum = [year intValue];
    NSMutableArray * array = [NSMutableArray new];
    for (int i = 2000 ; i < yerarNum  +1; i ++) {
        [array addObject:[NSString stringWithFormat:@"%d年",i]];
    }
    return array;
}
- (NSArray*)monthArray{

    NSMutableArray * array = [NSMutableArray new];
    for (int i = 1 ; i < 13  ; i ++) {
        [array addObject:[NSString stringWithFormat:@"%d月",i]];
    }
    return array;
}
#pragma mark --Action Method
- (void)onSelectedYearButton{
  //  self.yerarButton.selected = !self.yerarButton.selected;
    STPickerViewController * vc = [[STPickerViewController alloc] initWithPickerArray:@[[self yearArray]] andWithHandle:^(NSArray<NSString *> *stringArray) {
        
        [self.yerarButton setTitle:stringArray.firstObject forState:UIControlStateNormal];
         [self.yerarButton makeImageRight];
    }];
    [self presentViewController:vc animated:NO completion:nil];
    
}
- (void)onSelectedMonthButton{
   // self.monthButton.selected = !self.monthButton.selected;
    STPickerViewController * vc = [[STPickerViewController alloc] initWithPickerArray:@[[self monthArray]] andWithHandle:^(NSArray<NSString *> *stringArray) {
        
        [self.monthButton setTitle:stringArray.firstObject forState:UIControlStateNormal];
        [self.monthButton makeImageRight];
    }];
    [self presentViewController:vc animated:NO completion:nil];
}

@end
